#!/bin/sh

if [ "$#" -ne 3 ]; then
    echo "Usage: $0 file_path old_string new_string"
    exit 1
fi

file_path="$1"
old_string="$2"
new_string="$3"

if [ ! -f "$file_path" ]; then
    echo "Error: The file '$file_path' does not exist."
    exit 1
fi

temp_file=$(mktemp)
awk -v old="$old_string" -v new="$new_string" '{gsub(old,new); print}' "$file_path" > "$temp_file" && mv "$temp_file" "$file_path"

if [ $? -eq 0 ]; then
    echo "String replacement was successful."
else
    echo "An error occurred during string replacement."
fi
